package com.smz.controller;

import com.smz.entity.TPost;
import com.smz.service.TPostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api
@RestController
public class TPostController {
    @Autowired
    private TPostService tPostService;

    @ApiOperation("查找全部部门")
    @GetMapping("findAllTPosts")
    public ResponseEntity<List<TPost>>findAllTPosts(){
        List<TPost> tPosts=tPostService.list();
        return ResponseEntity.ok(tPosts);
    }

    @ApiOperation("更新部门")
    @PutMapping("tPost")
    public ResponseEntity<String>updateTPost(@RequestBody TPost tPost){
        tPostService.saveOrUpdate(tPost);
        return  ResponseEntity.ok("ok");
    }
    @ApiOperation("增加部门")
    @PostMapping("tPost")
    public ResponseEntity<String>addTPost(@RequestBody TPost tPost){
        tPostService.saveOrUpdate(tPost);
        return  ResponseEntity.ok("ok");
    }
    @ApiOperation("删除部门")
    @DeleteMapping("tPost")
    public  ResponseEntity<String>deleteTPost(@PathVariable("id")Integer id){
        tPostService.removeById(id);
        return ResponseEntity.ok("ok");
    }


    @ApiOperation("通过id职位")
    @GetMapping("/tPost/{id}")
    public ResponseEntity<TPost> findTPostById(@PathVariable("id")Integer id){
        TPost tPost = tPostService.findTPostById(id);
        return ResponseEntity.ok(tPost);
    }

    @ApiOperation("通过id查询职位")
    @GetMapping("/tPosts/{id}")
    public ResponseEntity<List<TPost>> findAllTPostsById(@PathVariable("id")Integer id){
        List<TPost> all =tPostService.findAllTPostById(id) ;
        return ResponseEntity.ok(all);
    }




}
